package com.wtwd.campus.dao;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.campus.entity.*;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * @Author ldaoliang
 * @Date create in 9:11 2021/6/22
 * @Description
 */
@Mapper
public interface CustomerMapper {

    /**
     * 根据appKey查询客户信息
     * @param appKey
     * @return
     */
    SysCustomer getCustomerInfoByAppKey(String appKey);

    /**
     * 修改用户推送地址
     * @param customerId
     * @param pushUrl
     * @return
     */
    int updatePushUrl(@Param("customerId")Integer customerId,@Param("pushUrl")String pushUrl,@Param("status")Integer status);

    /**
     * 根据客户id查询客户信息
     * @param customerId
     * @return
     */
    SysCustomer getCustomerInfoById(@Param("customerId") Integer customerId);

    /**
     * 保存推送失败数据
     * @param customerId
     * @param imei
     * @param data
     * @return
     */
    int saveFailedPushData(@Param("customerId") Integer customerId, @Param("imei") String imei, @Param("data") String data);

    /**
     * 获取设备白名单列表
     * @param imei
     * @return
     */
    List<WhiteCallVo> getDeviceWhiteCallList(@Param("imei") String imei);

    /**
     * 查询白名单数据
     * @param deviceId
     * @param sequence
     * @return
     */
    DeviceWhiteCall getDeviceWhiteCallByDeviceIdAndSequence(@Param("deviceId") Integer deviceId, @Param("sequence") Integer sequence);

    /**
     * 获取设备课堂模式列表
     * @param imei
     * @return
     */
    List<ClassPatternVo> getDeviceClassPatternList(@Param("imei") String imei);

    /**
     * 获取课堂模式
     * @param deviceId
     * @param sequence
     * @return
     */
    ClassPatternVo getClassPatternByDeviceIdAndSequence(@Param("deviceId") Integer deviceId, @Param("sequence") Integer sequence);

    /**
     * 获取系统客户列表
     * @return
     */
    IPage<SysCustomer> getSysCustomerList(@Param("page") Page<SysCustomer> page, @Param("customer") String customer);

    /**
     * 根据客户名获取客户信息
     * @param customerName
     * @return
     */
    SysCustomer getSysCustomerByName(@Param("customerName") String customerName);

    /**
     * 添加客户
     * @param customerName
     * @param appKey
     * @param appSecret
     * @param createTime
     * @return
     */
    int addSysCustomer(@Param("customerName") String customerName, @Param("appKey") String appKey, @Param("appSecret") String appSecret,
                       @Param("createTime")Long createTime);

    /**
     * 更新客户id
     * @param customerId
     * @param customerName
     * @return
     */
    int updateCustomer(@Param("customerId")Integer customerId,@Param("customerName")String customerName);

    /**
     * 开启关闭客户
     * @param customerId
     * @param onOff
     * @return
     */
    int startDisableCustomer(@Param("customerId")Integer customerId,@Param("onOff")Integer onOff);

    /**
     * 保存推送数据
     * @param imei
     * @param messageType
     * @param dataType
     * @param commandNumber
     * @param pushContent
     * @param pushTime
     * @return
     */
    int savePushData(@Param("imei") String imei, @Param("messageType") Integer messageType, @Param("dataType") Integer dataType,
                     @Param("commandNumber") String commandNumber, @Param("pushContent") String pushContent,@Param("pushTime")String pushTime);

    /**
     * 查看推送记录
     * @param imei
     * @return
     */
    @MapKey("id")
    List<Map<String,Object>> getPushRecord(@Param("imei")String imei);

    /**
     * 添加客户设备围栏
     * @param customerFence
     * @return
     */
    int addCustomerFence(CustomerFence customerFence);

    /**
     * 更新客户围栏
     * @param customerFence
     * @return
     */
    int updateCustomerFence(CustomerFence customerFence);

    /**
     * 根据id获取客户围栏
     * @param id
     * @return
     */
    CustomerFence getCustomerFenceById(Integer id);

    /**
     * 删除客户围栏
     * @param id
     * @return
     */
    int delCustomerFence(Integer id);

    /**
     * 获取设备围栏列表
     * @param imei
     * @return
     */
    @MapKey("id")
    List<CustomerFence> getDeviceFenceList(String imei);

    /**
     * 绑定客户学生设备
     * @param imei
     * @param stuName
     * @return
     */
    int bindCusStudent(@Param("imei") String imei, @Param("stuName") String stuName);

    /**
     * 获取设备的sos列表
     * @param deviceId
     * @return
     */
    List<DeviceSOSList> getDeviceSosPhoneList(Integer deviceId);

    /**
     * 添加sos号码
     * @param deviceId
     * @param sequence
     * @param name
     * @param phone
     * @param status
     * @param commandNumber
     * @return
     */
    int addSosPhone(@Param("deviceId") Integer deviceId, @Param("sequence") Integer sequence, @Param("name") String name,
                    @Param("phone") String phone, @Param("status") Integer status, @Param("commandNumber") String commandNumber);

    /**
     * 更新sos号码的状态
     * @param deviceId
     * @param status
     * @param sequence
     * @param commandNumber
     * @return
     */
    int updateSosPhoneStatus(@Param("deviceId") Integer deviceId, @Param("status") Integer status,
                             @Param("sequence") Integer sequence, @Param("commandNumber") String commandNumber);
}
